/* 
 * File:   expression.h
 * Author: abadalya
 *
 * Created on November 25, 2011, 3:44 PM
 */

#ifndef EXPRESSION_H
#define	EXPRESSION_H

enum expression_type { 
    T_UNDEFINED, 
    T_BINARY, 
    T_UNARY,
    T_APPLY,
    T_BRANCHING,
    T_CONSTANTA,
    T_VARIABLE,
    T_INPUT,
    T_PRINT
};

enum operation {
    O_DUMMY,
    O_ADD, O_SUB, O_MUL, O_DIV, O_MOD,
    O_EQ, O_NE, O_GT, O_GE, O_LT, O_LE,
    O_AND, O_OR, O_NOT
};

struct funcall;

struct expression {
    enum expression_type type;
    struct expression *first;
    struct expression *second;
    struct expression *third;
    enum operation oper;
    struct funcall* fcall;
    double value;
    char* name;
};

/* Constructors */
extern struct expression* create_zero_expression();
extern struct expression* create_constanta(double);
extern struct expression* create_variable(const char*);
extern struct expression* create_unary(enum operation, struct expression*);
extern struct expression* create_binary(enum operation, struct expression*, struct expression*);
extern struct expression* create_funcall_expression(struct funcall*);
extern struct expression* create_branching_expression(struct expression*, struct expression*, struct expression*);
extern struct expression* create_input_expression();
extern struct expression* create_print_expression(struct expression*);
extern void destroy_expression(struct expression*);

/* Evaluator */
struct symbol_table;
extern double evaluate(struct expression*, struct symbol_table*);
extern void print_expression(struct expression*);

#endif	/* EXPRESSION_H */

